{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## ch02"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "message='hello python world'\n",
    "print(message)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## ch03"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#0301 列表\n",
    "bicycles=['trek','cannondale','redline','specialized']\n",
    "print(bicycles)\n",
    "#\n",
    "#访问列表元素\n",
    "print(bicycles[0])\n",
    "print(bicycles[1])\n",
    "print(bicycles[3])\n",
    "print(bicycles[-1])\n",
    "\n",
    "#使用列表中的各个值\n",
    "message='my first bicycle was a '+bicycles[0].title()+'.'\n",
    "print(message)\n",
    "\n",
    "##修改列表元素\n",
    "motorcycles=['honda','yamaha','suzuki']\n",
    "print(motorcycles)\n",
    "\n",
    "motorcycles[0]='ducati'\n",
    "print(motorcycles)\n",
    "#添加列表元素\n",
    "motorcycles.append('ducati')#在末尾处添加\n",
    "print(motorcycles)\n",
    "motorcycles.insert(0,'ducati')#在0位添加\n",
    "print(motorcycles)\n",
    "\n",
    "#先创建空列表，后向里面添加元素\n",
    "motorcycles=[]\n",
    "motorcycles.append('honda')\n",
    "motorcycles.append('yamaha')\n",
    "motorcycles.append('suzuki')\n",
    "print(motorcycles)\n",
    "#列表删除元素\n",
    "del motorcycles[0]\n",
    "print(motorcycles)\n",
    "#Pop()函数，弹出列表中最后的元素\n",
    "\n",
    "motorcycles=['a','b','c']\n",
    "print(motorcycles)\n",
    "#所以一般执行这个函数的时候就要赋值，才能将踢出的元素保存\n",
    "\n",
    "motorcycles.pop()\n",
    "print(motorcycles)\n",
    "\n",
    "poped_motorcycles=motorcycles.pop()\n",
    "print(motorcycles)\n",
    "print(poped_motorcycles)\n",
    "\n",
    "motorcycles=['honda','ymaha','suzuki']\n",
    "last_owned=motorcycles.pop()\n",
    "print('The last motorcycle I owoned was a '+last_owned.title()+'.')\n",
    "\n",
    "#弹出列表中任意位置的元素\n",
    "\n",
    "first_owned=motorcycles.pop(0)\n",
    "print('The first motorcycle I owned was a '+first_owned.title()+'.')\n",
    "\n",
    "#根据值删除元素\n",
    "motorcycles=['honda','yamaha','suzuki','ducati']\n",
    "print(motorcycles)\n",
    "motorcycles.remove('ducati')\n",
    "print(motorcycles)\n",
    "#remove删除\n",
    "too_expensive='suzuki'\n",
    "motorcycles.remove(too_expensive)\n",
    "print(motorcycles)\n",
    "print('\\nA '+too_expensive.title()+' is too expensive for me')\n",
    "motorcycles.remove('honda')\n",
    "print(motorcycles)\n",
    "\n",
    "#对列表元素按首字母进行永久性排序\n",
    "cars=['bmw','audi','toyota','subaru']\n",
    "cars.sort()\n",
    "print(cars)\n",
    "#列表元素首字母永久性反序\n",
    "cars.sort(reverse=True)\n",
    "print(cars)\n",
    "#临时排序，调用函数:y=f(x),本身的x没有变；x.f()相当于x=f(x)，x本身变了\n",
    "print('Here is the ariginal list:')\n",
    "print(cars)\n",
    "print('\\nHere is the sorted list:')\n",
    "print(sorted(cars))\n",
    "print('\\nHere is the original list again:')\n",
    "print(cars)\n",
    "\n",
    "#倒着打印，倒序打印列表\n",
    "print(cars)\n",
    "cars.reverse()\n",
    "print(cars)\n",
    "#\n",
    "#列表长度\n",
    "print(len(cars))\n",
    "\n",
    "\n",
    "\n",
    "# 0302习题3-1 姓名列表，访问元素，打印出来\n",
    "onepiece=['Monkey·D·Luffy','Roronoa Zoro','Nami','Usopp','Sanji'\n",
    ",'Tony-Tony Chopper','Nico Robin','Franky','Brook','Jinbe','Carrot']\n",
    "\n",
    "print(onepiece[0])\n",
    "print(onepiece[1])\n",
    "print(onepiece[2])\n",
    "print(onepiece[3])\n",
    "print(onepiece[4])\n",
    "print(onepiece[-6])\n",
    "print(onepiece[-5])\n",
    "print(onepiece[-4])\n",
    "print(onepiece[-3])\n",
    "print(onepiece[-2])\n",
    "print(onepiece[-1])\n",
    "\n",
    "\n",
    "# 0302习题3-2 姓名列表，打印人名+问候语\n",
    "print(\"Love you，\"+onepiece[0])\n",
    "print(\"Love you，\"+onepiece[1])\n",
    "print(\"Love you，\"+onepiece[2])\n",
    "print(\"Love you，\"+onepiece[3])\n",
    "print(\"Love you，\"+onepiece[4])\n",
    "print(\"Love you，\"+onepiece[-6])\n",
    "print(\"Love you，\"+onepiece[-5])\n",
    "print(\"Love you，\"+onepiece[-4])\n",
    "print(\"Love you，\"+onepiece[-3])\n",
    "print(\"Love you，\"+onepiece[-2])\n",
    "print(\"Love you，\"+onepiece[-1])\n",
    "\n",
    "# 0302 习题3-3 通勤方式列表，打印一些列有关通勤方式的宣言\n",
    "transport=[\"大妈\",'路飞','leijiu']\n",
    "print(transport[0]+'是我的最最理想型')\n",
    "\n",
    "# 0302 习题3-4 邀请晚宴名单 发出邀请\n",
    "onepiece=['Monkey·D·Luffy','Roronoa Zoro','Nami','Usopp','Sanji'\n",
    ",'Tony-Tony Chopper','Nico Robin','Franky','Brook','Jinbe','Carrot']\n",
    "\n",
    "print(\"Welcome to the wedding, \"+onepiece[0])\n",
    "print(\"Welcome to the wedding, \"+onepiece[1])\n",
    "print(\"Welcome to the wedding, \"+onepiece[2])\n",
    "print(\"Welcome to the wedding, \"+onepiece[3])\n",
    "print(\"Welcome to the wedding, \"+onepiece[4])\n",
    "print(\"Welcome to the wedding, \"+onepiece[-6])\n",
    "print(\"Welcome to the wedding, \"+onepiece[-5])\n",
    "print(\"Welcome to the wedding, \"+onepiece[-4])\n",
    "print(\"Welcome to the wedding, \"+onepiece[-3])\n",
    "print(\"Welcome to the wedding, \"+onepiece[-2])\n",
    "print(\"Welcome to the wedding, \"+onepiece[-1])\n",
    "\n",
    "\n",
    "# 习题3-5 修改嘉宾名单\n",
    "a=onepiece[1]\n",
    "onepiece.remove(a)\n",
    "print(a+' cannot come.')\n",
    "onepiece.append('老鹰记者')\n",
    "print(\"Welcome to the wedding, \"+onepiece[0])\n",
    "print(\"Welcome to the wedding, \"+onepiece[1])\n",
    "print(\"Welcome to the wedding, \"+onepiece[2])\n",
    "print(\"Welcome to the wedding, \"+onepiece[3])\n",
    "print(\"Welcome to the wedding, \"+onepiece[4])\n",
    "print(\"Welcome to the wedding, \"+onepiece[-6])\n",
    "print(\"Welcome to the wedding, \"+onepiece[-5])\n",
    "print(\"Welcome to the wedding, \"+onepiece[-4])\n",
    "print(\"Welcome to the wedding, \"+onepiece[-3])\n",
    "print(\"Welcome to the wedding, \"+onepiece[-2])\n",
    "print(\"Welcome to the wedding, \"+onepiece[-1])\n",
    "\n",
    "# 3-6\n",
    "\n",
    "onepiece.insert(0,'Germa')\n",
    "onepiece.insert(4,'Fire Tank')\n",
    "onepiece.append('Big Mom')\n",
    "print(\"Welcome to the wedding, \"+onepiece[0])\n",
    "print(\"Welcome to the wedding, \"+onepiece[1])\n",
    "print(\"Welcome to the wedding, \"+onepiece[2])\n",
    "print(\"Welcome to the wedding, \"+onepiece[3])\n",
    "print(\"Welcome to the wedding, \"+onepiece[4])\n",
    "print(\"Welcome to the wedding, \"+onepiece[5])\n",
    "print(\"Welcome to the wedding, \"+onepiece[6])\n",
    "print(\"Welcome to the wedding, \"+onepiece[7])\n",
    "print(\"Welcome to the wedding, \"+onepiece[-6])\n",
    "print(\"Welcome to the wedding, \"+onepiece[-5])\n",
    "print(\"Welcome to the wedding, \"+onepiece[-4])\n",
    "print(\"Welcome to the wedding, \"+onepiece[-3])\n",
    "print(\"Welcome to the wedding, \"+onepiece[-2])\n",
    "print(\"Welcome to the wedding, \"+onepiece[-1])\n",
    "\n",
    "# 3-7\n",
    "print(\"\\nSorry, there are only two places left\")\n",
    "a=onepiece.pop(-1)\n",
    "print(\"The wedding is canceled, franchement desole, \"+a)\n",
    "\n",
    "a=onepiece.pop(-1)\n",
    "print(\"The wedding is canceled, franchement desole, \"+a)\n",
    "\n",
    "a=onepiece.pop(-1)\n",
    "print(\"The wedding is canceled, franchement desole, \"+a)\n",
    "\n",
    "a=onepiece.pop(-1)\n",
    "print(\"The wedding is canceled, franchement desole, \"+a)\n",
    "\n",
    "a=onepiece.pop(-1)\n",
    "print(\"The wedding is canceled, franchement desole, \"+a)\n",
    "\n",
    "a=onepiece.pop(-1)\n",
    "print(\"The wedding is canceled, franchement desole, \"+a)\n",
    "\n",
    "a=onepiece.pop(-1)\n",
    "print(\"The wedding is canceled, franchement desole, \"+a)\n",
    "\n",
    "a=onepiece.pop(-1)\n",
    "print(\"The wedding is canceled, franchement desole, \"+a)\n",
    "\n",
    "a=onepiece.pop(-1)\n",
    "print(\"The wedding is canceled, franchement desole, \"+a)\n",
    "\n",
    "a=onepiece.pop(-1)\n",
    "print(\"The wedding is canceled, franchement desole, \"+a)\n",
    "\n",
    "\n",
    "a=onepiece.pop(-1)\n",
    "print(\"The wedding is canceled, franchement desole, \"+a)\n",
    "\n",
    "a=onepiece.pop(-1)\n",
    "print(\"The wedding is canceled, franchement desole, \"+a)\n",
    "\n",
    "print(onepiece)\n",
    "\n",
    "# 对剩下的两位，打印一句话\n",
    "print('\\n有缘千里来相会，雷玖在等你'+onepiece[1])\n",
    "print('我从远方赶来赴你一面之约'+onepiece[0])\n",
    "\n",
    "# 删除余下两位\n",
    "\n",
    "del onepiece[0]\n",
    "del onepiece[1]\n",
    "\n",
    "print(onepiece)\n",
    "\n",
    "\n",
    "\n",
    "# 0303 习题 3-8 放眼世界，想出至少5个你想去的地方，顺序打乱\n",
    "to_the_places_I_belong=['swizerland','my side','higher dimentional space','my home','argentina']\n",
    "\n",
    "# 打印原始列表\n",
    "print(\"The original list:\\n\")\n",
    "print(to_the_places_I_belong)\n",
    "#\n",
    "# sorted()按字母顺序打印，不改变原来列表的顺序\n",
    "print(\"\\nSorted list:\\n\")\n",
    "print(sorted(to_the_places_I_belong))\n",
    "\n",
    "# 再次打印确认列表顺序没变\n",
    "print(\"\\nThe original list again:\\n\")\n",
    "print(to_the_places_I_belong)\n",
    "\n",
    "# sorted()反序，不改变列表原来顺序,reverse=Ture\n",
    "\n",
    "print(\"The list after being sorted_reverse=True:\\n\")\n",
    "print(sorted(to_the_places_I_belong,reverse=True))\n",
    "\n",
    "# 再次打印确认列表顺序没变\n",
    "print(\"\\nThe original list again:\\n\")\n",
    "print(to_the_places_I_belong)\n",
    "\n",
    "#reverse反转，改变原列表的顺序\n",
    "print('\\n用reverse反转的效果\\n')\n",
    "to_the_places_I_belong.reverse()\n",
    "print(to_the_places_I_belong)\n",
    "\n",
    "#reverse()再次反转\n",
    "print(\"\\n用reverse再次反转列表的效果\\n\")\n",
    "to_the_places_I_belong.reverse()\n",
    "print(to_the_places_I_belong)\n",
    "\n",
    "#sort()改变列表本身的顺序\n",
    "\n",
    "print('\\nThe list after being ordered by sort()\\n')\n",
    "to_the_places_I_belong.sort()\n",
    "print(to_the_places_I_belong)\n",
    "\n",
    "#sort()反序\n",
    "\n",
    "\n",
    "print('\\nThe list after being ordered by sort(reverse=Ture)\\n')\n",
    "to_the_places_I_belong.sort(reverse=True)\n",
    "print(to_the_places_I_belong)\n",
    "\n",
    "\n",
    "# 0304 习题3-9 哎呀，早说呀，我怎么把len()这个函数给忘了\n",
    "\n",
    "onepiece=['Monkey·D·Luffy','Roronoa Zoro','Nami','Usopp','Sanji'\n",
    ",'Tony-Tony Chopper','Nico Robin','Franky','Brook','Jinbe','Carrot']\n",
    "\n",
    "# print(len(onepiece))\n",
    "\n",
    "\n",
    "# 0304 习题 3-10 自建列表，尝试使用本章的所有函数\n",
    "\n",
    "# 1.访问\n",
    "# 2.修改\n",
    "# 索引直怼\n",
    "# print(onepiece)\n",
    "# onepiece[0]='Charlotte Linlin'\n",
    "# print(onepiece)\n",
    "\n",
    "# 3.添加\n",
    "\n",
    "onepiece.append('Charlotte Linlin')#末尾添加\n",
    "print(onepiece)\n",
    "onepiece.insert(0,'Shanks')#根据索引插入\n",
    "print(onepiece)\n",
    "\n",
    "# 4.删除\n",
    "print(onepiece)\n",
    "del onepiece[2]#根据索引删除，特点是删了就删了，这个值不能给别人\n",
    "print(onepiece)\n",
    "\n",
    "a=onepiece.pop(2)\n",
    "#默认弹出最后一个，特点从列表中弹出，可以给别人\n",
    "#需要知道索引位置\n",
    "print(a)\n",
    "print(onepiece)\n",
    "\n",
    "\n",
    "a=onepiece.remove('Monkey·D·Luffy')\n",
    "print(onepiece)\n",
    "print(a)\n",
    "\n",
    "# 特点，不知道索引位置，知道元素是什么\n",
    "# remove出去的元素不可以通过赋值继续使用\n",
    "# 剩下就是对列表一顿操作的函数，各种排序，上一道题做过了，不想搞了\n",
    "\n",
    "# 0305 3-11 有意引发错误\n",
    "\n",
    "list=['a','b','c']\n",
    "list[0]\n",
    "a=list.remove('c')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "懒得分块了，将就吧，都在这里了"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
